//
//  NoteTagMigration.swift
//  hello
//
//  Created by 赵康 on 2025/3/26.
//

  // CreateNoteTag.swift

import Fluent

extension NoteTag {
  struct Migration: AsyncMigration {
    var name: String { "NoteTagMigration" }
    
    func prepare(on database: Database) async throws {
      try await database.schema(SchemaEnum.noteTags.rawValue)
        .id()
        .field(FieldKeys.name, .string, .required)
        .field(FieldKeys.user, .uuid, .required, .references(SchemaEnum.users.rawValue, "id"))
        .field(FieldKeys.createdAt, .datetime)
        .field(FieldKeys.updatedAt, .datetime)
        .unique(on: FieldKeys.name, FieldKeys.user)
        .create()
    }
    
    func revert(on database: Database) async throws {
      try await database.schema(SchemaEnum.noteTags.rawValue).delete()
    }
  }
}
